<template>
  <a-modal
    :maskClosable="false"
    :title="title"
    width="75vw"
    centered
    :bodyStyle="{
      padding: '0 24px',
    }"
    :visible="visible"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-card
      :bordered="false"
      :bodyStyle="{
        padding: '10px 24px',
      }"
      style="width: 100%; height: 80vh; overflow-y: auto;"
    >
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchByquery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="档案编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input placeholder="请输入档案编号" v-model="queryParam.billNo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <!-- <select-project-input ref="projectModel" v-model="queryParam.projectName"/> -->
                <j-input placeholder="请输入项目名称" v-model="queryParam.projectName"></j-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="经营团队" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <select-team-input v-model="queryParam.teamName" :tdlx="1" :teamType="0"/>
              </a-form-item>
            </a-col>

            <template v-if="toggleSearchStatus">

              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="项目承接人">
                  <j-input placeholder="请输入项目承接人" v-model="queryParam.undertakerName"></j-input>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="业主单位">
                  <j-input placeholder="请输入业主单位" v-model="queryParam.enterpriseName"></j-input>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="收款合同名称">
                  <j-input placeholder="请输入收款合同名称" v-model="queryParam.contractName"></j-input>
                </a-form-item>
              </a-col>
              <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="合同档案状态" :labelCol="labelCol">
                <j-dict-select-tag placeholder="请选择合同档案状态" v-model="queryParam.status" dictCode="contract_final_status"/>
              </a-form-item>
            </a-col> -->

              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-model-item label="业务分类" :labelCol="labelCol">
                  <business-category-name-select v-model="queryParam.categoryCode" @back="businessCategoryHandle"/>
                </a-form-model-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="合同分配额(元)" :labelCol="labelCol">
                  <a-input-number
                    :precision="2"
                    placeholder="请输入最小值"
                    class="query-group-cust"
                    v-model="queryParam.contractAmount_begin"
                    @change="(val) => this.contractAmountRange = parseInt(val)"
                    style="width: 45%"
                    :min="0"
                    :max="999999999"/>
                  -
                  <a-input-number
                    :precision="2"
                    placeholder="请输入最大值"
                    class="query-group-cust"
                    v-model="queryParam.contractAmount_end"
                    style="width: 45%"
                    :min="contractAmountRange"
                    :max="999999999"/>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <!-- @change="sctdChange" -->
                <a-form-model-item label="生产团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productTeam">
                  <select-team-input
                    placeholder="请选择生产团队"
                    v-model="queryParam.productTeam"
                    :tdlx="2"
                    :teamType="0"
                    :triggerChange="true"/>
                </a-form-model-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="实施部门" :labelCol="labelCol" prop="executeDepart">
                  <j-select-depart placeholder="请选择实施部门" v-model="queryParam.executeDepart"/>
                </a-form-item>
              </a-col>
              <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="预计合同额(元)" :labelCol="labelCol">
                <a-input-number
                  :precision="2"
                  placeholder="请输入最小值"
                  class="query-group-cust"
                  v-model="queryParam.estimatedContractAmount_begin"
                  @change="(val) => this.estimatedContractAmountRange = parseInt(val)"
                  style="width: 45%"
                  :min="0"
                  :max="999999999"/>
                -
                <a-input-number
                  :precision="2"
                  placeholder="请输入最大值"
                  class="query-group-cust"
                  v-model="queryParam.estimatedContractAmount_end"
                  style="width: 45%"
                  :min="estimatedContractAmountRange"
                  :max="999999999"/>
              </a-form-item>
            </a-col> -->

              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="部门负责人" :labelCol="labelCol" prop="deptLeadName">
                  <!-- <select-user-by-dep :multi="false" v-model="queryParam.deptLeadName"/> -->
                  <j-input placeholder="请输入部门负责人" v-model="queryParam.deptLeadName"></j-input>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="项目负责人" :labelCol="labelCol" prop="projLeadName">
                  <j-input placeholder="请输入项目负责人" v-model="queryParam.projLeadName"></j-input>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-model-item label="任务进度" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input-number
                    :precision="2"
                    placeholder="请输入最小值"
                    class="query-group-cust"
                    v-model="queryParam.taskProgress_begin"
                    @change="(val) => this.contractRateRange = parseInt(val)"
                    style="width: 45%"
                    :min="0"
                    :max="100"/>
                  -
                  <a-input-number
                    :precision="2"
                    placeholder="请输入最大值"
                    class="query-group-cust"
                    v-model="queryParam.taskProgress_end"
                    style="width: 45%"
                    :min="contractRateRange"
                    :max="100"/>
                </a-form-model-item>
              </a-col>
              <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="是否变更中" :labelCol="labelCol" prop="changeStatus">
                  <j-dict-select-tag placeholder="请选择是否变更中" v-model="queryParam.changeStatus" dictCode="change_status"/>
                </a-form-item>
              </a-col> -->
              <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="isExcludeWaitingStatus">
                <a-form-item label="状态" :labelCol="labelCol" prop="distributionType">
                  <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.distributionType" dictCode="distribution_type_replace"/>
                </a-form-item>
              </a-col>
            </template>
            <a-col style="float: left;overflow: hidden;" :xl="6" :lg="7" :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchByquery" icon="search">查询</a-button>
                <a-button @click="searchReset(1)" icon="reload" style="margin-left: 8px;">重置</a-button>
                <a @click="handleToggleSearch" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <a-table
        ref="table"
        rowKey="id"
        bordered
        :scroll="{x:scrollX}"
        :columns="dragResizeColumns"
        :components="draggableComponent"
        :dataSource="dataSource"
        :loading="loading"
        :pagination="ipagination"
        :rowSelection="{
          selectedRowKeys: selectedRowKeys,
          onSelectAll: onSelectAll,
          onSelect: onSelectOne,
          onChange: onSelectChange,
          // getCheckboxProps: getCheckboxProps,
          type: getType,
        }"
        @change="handleTableChange"
        class="j-table-force-nowrap"
        wrapClassName="ant-modal-cust-warp"
      >
        <span slot="projectName" slot-scope="text,record">
          <a href="javascript:void(0);" @click="goProjectDetail(record)">{{ text }}</a>
        </span>
      </a-table>
      <span slot="action" slot-scope="text, record" class="table-operation">
        <a @click="onDetail(record)">详情</a>
      </span>
    </a-card>
    <!-- 项目详情开始 -->
    <erp-project-report-modal ref="projectReport"></erp-project-report-modal>
    <!-- 项目详情结束 -->
  </a-modal>
</template>

<script>
import { filterObj } from '@/utils/util'
import { queryDepartTreeList, searchByKeywords } from '@/api/api'
import { getAction } from '@/api/manage'
import Area from '@/components/_util/Area'
import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
import address from '@/components/AddressChoice/address.js'
import BusinessCategoryNameSelect from '@views/erp/components/BusinessCategoryNameSelect'
import { filterMultiDictText } from '@comp/dict/JDictSelectUtil';
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
import { DragResizable } from '@/mixins/DragResizable'
export default {
  name: 'SelectTaskFileModal',
  components: {
    SelectTeamInput,
    SelectCompanyInput,
    ErpProjectReportModal: () => import('@/views/erp/report/project/modules/ErpProjectReportModal'),
    BusinessCategoryNameSelect
  },
  mixins: [DragResizable],
  props: ['isProjectTaskId', 'isFlowCancel', 'useType', 'dataType', 'dataIsolation', 'multi', 'tenderStatus', 'projectId', 'urlList', 'proDisabled', 'projectStatus', 'changeStatus', 'signUnit', 'costType', 'teamId', 'undertaker', 'isBidding', 'isContractManager', 'isExcludeWaitingStatus', 'customDistributionType','isProjectArchive','billType'],
  data() {
    return {
      labelCol: {
        span: 8
      },
      wrapperCol: {
        span: 16
      },
      address: address,
      title: '选择任务',
      queryParam: {
        isBidding: this.isBidding,
        status: this.projectStatus,
        signUnit: this.signUnit,
        teamName2: this.teamId,
        projectTenderStatus: this.tenderStatus,
        dataIsolation: this.dataIsolation,
        costType: this.costType,
        undertaker: this.undertaker
      },
      disableStatus: '1',
      dragResizeColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }
        },
        {
          title: '档案编号',
          align: 'center',
          dataIndex: 'billNo',
          width:186,
          ellipsis: true,
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
          width:125,
          ellipsis: true,
          scopedSlots: { customRender: 'projectName' },
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }
        },
        {
          title: '经营团队',
          align: 'center',
          dataIndex: 'signteamName',
          width:256,
          ellipsis: true,
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }
        },
        {
          title: '项目承接人',
          align: 'center',
          dataIndex: 'undertakerName',
          width:110,
          ellipsis: true,
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }

        },
        {
          title: '业主单位',
          align: 'center',
          dataIndex: 'enterpriseName',
          width:212,
          ellipsis: true,
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }
        },
        {
          title: '收款合同名称',
          align: 'center',
          dataIndex: 'contractName',
          width:130,
          ellipsis: true,
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }
        },
        {
          title: '业务分类',
          align: 'center',
          dataIndex: 'categoryName',
          width:90,
          ellipsis: true,
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }
        },
        {
          title: '合同分配额(元)',
          align: 'center',
          dataIndex: 'contractAmount',
          width:135,
          ellipsis: true,
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }
        },
        {
          title: '生产团队',
          align: 'center',
          dataIndex: 'productTeam_dictText',
          width:120,
          ellipsis: true,
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }
        },
        {
          title: '实施部门',
          align: 'center',
          dataIndex: 'executeDepart_dictText',
          width:100,
          ellipsis: true,
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }

        },
        {
          title: '部门负责人',
          align: 'center',
          dataIndex: 'deptLeadName',
          width:110,
          ellipsis: true,
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }

        },
        {
          title: '项目负责人',
          align: 'center',
          dataIndex: 'projLeadName',
          width:110,
          ellipsis: true,
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }
        },
        {
          title: '任务进度(%)',
          align: 'center',
          dataIndex: 'taskProgress',
          width:120,
          ellipsis: true,
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }
        },
        // {
        //   title: '是否变更中',
        //   align: 'center',
        //   dataIndex: 'changeStatus_dictText',
        //   customCell: (record, index) => {
        //     let that = this
        //     return {
        //       on: {
        //         click: () => {
        //           that.selectedRowKeys = []
        //           that.selectedRowKeys.push(record.id)
        //           that.choseObj = []
        //           that.choseObj.push(record)
        //         }
        //       }
        //     }
        //   }
        // },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'distributionType_dictText',
          width:80,
          ellipsis: true,
          customCell: (record, index) => {
            let that = this
            return {
              on: {
                click: () => {
                  that.selectedRowKeys = []
                  that.selectedRowKeys.push(record.id)
                  that.choseObj = []
                  that.choseObj.push(record)
                }
              }
            }
          }
        }
      ],

      dataSource: [],
      choseObj: [],
      departTree: [],
      selectedKeys: [],
      iExpandedKeys: [],
      orgCode: '',
      loading: false,
      treeData: [],
      checkedKeys: [],
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30', '50', '100', '200'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      // isorter: {
      //   column: 'createTime',
      //   order: 'desc'
      // },
      url: {
        queryProjectReportById: '/api/erp/project/report/erpProjectReport/queryById',
        queryById: '/api/erp/omc/project/erpOmcProjectTaskFinal/queryPageList',
        urlList: '/api/erp/omc/project/erpOmcProjectTaskFinal/queryPageList',
        projectUrlList: '/api/erp/omc/project/erpOmcProject/queryOmcProjectList'
      },
      scrollTrigger: { x: true },
      selectedRowKeys: [],
      selectionRows: [],
      visible: false,
      toggleSearchStatus: false,
      pcaData: '',
      signUnitFlag: false,
      teamIdFlag: false,
      undertakerFlag: false,

      estimatedContractAmountRange: 0,
      contractAmountRange: 0,
      contractRateRange: 0
    }
  },
  created() {
    this.pcaData = new Area()
    // if (this.signUnit) {
    //   this.signUnitFlag = true
    // } else {
    //   this.signUnitFlag = false
    // }
    // if (this.teamId) {
    //   this.teamIdFlag = true
    // } else {
    //   this.teamIdFlag = false
    // }
    // this.loadData()
    // 该方法触发屏幕自适应
    this.resetScreenSize()
    this.refresh()
    this.initSource()
    this.dragResizeColumnswidth = this.dragResizeColumns.map(val => {
      return val.width
    })
  },
  computed: {
    // 计算属性的 getter
    getType: function () {
      return this.multi == true ? 'checkbox' : 'radio'
    },
    queryXmztStatus () {
      if (this.proDisabled) {
        if (this.projectStatus && this.projectStatus === '1') {
          this.disableStatus = '2'
        }
        return this.proDisabled;
      } else {
        this.disableStatus = '1'
        return false;
      }
    }
  },
  watch: {
    projectId: {
      handler (value) {
        if (value) {
          this.queryParam.projectId = this.projectId;
          this.loadData();
        }
      },
      immediate: true
    },
    isFlowCancel: {
      handler (value) {
        if (value) {
          this.queryParam.isFlowCancel = this.isFlowCancel;
          this.loadData();
        }
      },
      immediate: true
    }
  },
  methods: {
    goProjectDetail(record) {
      const that = this
        this.$nextTick(() => {
          getAction(this.url.queryProjectReportById, { id: record.projectId }).then((res) => {
            if (res.success) {
              const model = res.result
              that.$refs.projectReport.getDetail(model);
              that.$refs.projectReport.title = '项目一览表';
            }
          })
        })
      },
    checkDataSource() {
      this.dataSource = []
      this.ipagination.total = 0
      this.loadData(1);
    },
     // 点击详情
      onDetail (record) {
        // let url = ''
        // if(!!this.deliveryStorage) {
        //   url = '/api/erp/purchase/recipients/erpPurchaseRecipientsDetail/allListTo'
        // } else {
        //   url = this.urlListDetail
        // }
        // getAction(url, { billId: record.id }).then((res) => {
        //    if (res.success) {
        //     this.dataSourceDetail = res.result
        //     this.visibleDetail = true
        //     this.visible = false
        //   }
        // })
      },
    add(selectObj, ids) {
      if (!this.projectId) {
        this.$message.warning('请先选择项目名称')
        return false
      }
      this.visible = true
      this.edit(selectObj, ids)
    },
    edit(selectObj, ids) {
      if (!ids) {
        this.selectedRowKeys = []
      } else {
        this.selectedRowKeys = ids
      }
      if (!selectObj) {
        this.selectionRows = []
      } else {
        this.selectionRows = selectObj
        this.choseObj = selectObj
      }
      if (ids == null && selectObj == null) {
        this.selectionRows = []
        this.choseObj = []
        this.selectedRowKeys = []
      }
    },
    loadData(arg, url) {
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      this.pageEnable = true
      var params = this.getQueryParams() // 查询条件
      params.sysOrgCode = this.orgCode
      let tmpUrl = this.urlList
      this.loading = true
      params.projectId = this.projectId
      params.isFlowCancel = this.isFlowCancel
      if (this.isProjectTaskId) {
        params.distributionType = 'producting'
      }else if (this.isProjectArchive){
        //项目存档单
        params.distributionType = 'finish,producting'
      }else if(this.billType === '1'){
        //报告审核单定制
        console.log('哈哈-billType');
        
        params.changeStatus = '!changing'
        params.distributionType = 'finish,producting'
      }
      else if(this.billType === 'contract'){
        // 合同定制
 
        params.distributionType = '!cancel'
        tmpUrl = '/api/erp/omc/project/erpOmcProjectTaskFinal/queryAllPageList'
      }
      else {
        //用于非项目存档单单据
        params.changeStatus = '!changing'
        if (!this.getQueryParams().distributionType) {
          params.distributionType = this.isExcludeWaitingStatus ? '!waiting' : 'waiting'
        }
        if (this.customDistributionType) {
          params.distributionType = this.customDistributionType
        }
      }

      // params.distributionType = 'waiting'
      getAction(tmpUrl, params).then((res) => {
        if (res.success) {
          if (res.result == null) {
            this.dataSource = []
            this.ipagination.total = 0
            return
          }
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total
          if (this.orgCode === '') {
            // 第一次打开
          } else {
            for (var i = 0; i < this.dataSource.length; i++) {
              for (var j = 0; j < this.choseObj.length; j++) {
                if (this.choseObj[j].id == this.dataSource[i].id) {
                  this.selectionRows.push(this.dataSource[i])
                  this.selectedRowKeys.push(this.dataSource[i].id)
                  break
                }
              }
            }
          }
          // 判断是否当前页没有数据且不为第一页
          if (this.dataSource.length == 0 && this.ipagination.current != 1) {
            this.ipagination.current = this.ipagination.current - 1
            this.loadData(this.ipagination.current - 1)
          }
        }
      }).finally(() => {
            this.loading = false
          })
    },
    loadTree() {
      var that = this
      that.treeData = []
      that.departTree = []
      queryDepartTreeList().then((res) => {
        if (res.success) {
          for (let i = 0; i < res.result.length; i++) {
            let temp = res.result[i]
            that.treeData.push(temp)
            that.departTree.push(temp)
            that.setThisExpandedKeys(temp)
          }
          this.loading = false
        }
      })
    },
    getQueryParams() {
      let param = Object.assign({}, this.queryParam)
      param.field = this.getQueryField()
      param.pageNo = this.ipagination.current
      param.pageSize = this.ipagination.pageSize
      return filterObj(param)
    },
    getCheckboxProps (record) {
      return {
          props: {
            disabled: !this.isProjectArchive && !this.isProjectTaskId && record.changeStatus !== 'unchanged', // Column configuration not to be checked
            projectName: record.projectName
          }
        }
    },
    getQueryField() {
      let str = 'id,'
      for (let a = 0; a < this.dragResizeColumns.length; a++) {
        str += ',' + this.dragResizeColumns[a].dataIndex
      }
      return str
    },
    onSelectAll(selected, selectedRows, changeRows) {
      if (selected === true) {
        for (var a = 0; a < changeRows.length; a++) {
          this.choseObj.push(changeRows[a])
        }
      } else {
        for (var b = 0; b < changeRows.length; b++) {
          this.choseObj.splice(this.choseObj.indexOf(changeRows[b]), 1)
        }
      }
    },
    onSelectOne(record, selected) {
      if (selected === true) {
        if (this.multi) {
          // 多选
          this.choseObj.push(record)
        } else {
          // 单选
          this.choseObj = []
          this.choseObj.push(record)
        }
      } else {
        if (this.multi) {
          // 多选
          var index = -1
          for (var i = 0; i < this.choseObj.length; i++) {
            if (this.choseObj[i].id == record.id) {
              index = i
              break
            }
          }
          if (index >= 0) {
            this.choseObj.splice(index, 1)
          }
        } else {
          // 单选
          this.choseObj = []
        }
      }
    },
    initSource() {
      this.selectedRowKeys = []
      this.selectionRows = []
      this.choseObj = []
    },

    businessCategoryHandle(obj) {
      if (obj) {
        this.queryParam.categoryCode = obj.categoryCode;
      }
    },

    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
    },
    searchReset() {
      let that = this
      Object.keys(that.queryParam).forEach(function (key) {
        if (key === 'status') {
          if (that.disableStatus === '1' && !that.projectStatus) {
            that.queryParam[key] = null
          }
        } else if (!!that.signUnit && key == 'signUnit') {
          that.queryParam[key] = that.queryParam[key]
        } else if (!!that.teamId && key == 'teamName2') {
          that.queryParam[key] = that.queryParam[key]
        } else if (!!that.costType && key == 'costType') {
          that.queryParam[key] = that.queryParam[key]
        } else {
          that.queryParam[key] = null
        }
      })
      this.dataSource = []
      this.ipagination.total = 0
      that.loadData(1)
    },
    handleTableChange(pagination, filters, sorter) {
      // TODO 筛选
      // if (Object.keys(sorter).length > 0) {
      //   this.isorter.column = sorter.field
      //   this.isorter.order = sorter.order == 'ascend' ? 'asc' : 'desc'
      // }
      this.ipagination = pagination
      this.ipagination.current = pagination.current
      this.loadData()
    },
    handleCancel() {
      this.selectionRows = []
      this.selectedRowKeys = []
      this.visible = false
    },
    handleOk() {
      let data = {
        choseObj: this.choseObj,
        cutStatus: ''
      }
      this.$emit('choseObj', data)
      this.handleCancel()
    },
    searchByquery() {
      this.loadData(1)
    },
    handleToggleSearch() {
      this.toggleSearchStatus = !this.toggleSearchStatus
    },
    onSearch(value) {
      let that = this
      if (value) {
        searchByKeywords({ keyWord: value }).then((res) => {
          if (res.success) {
            that.departTree = []
            for (let i = 0; i < res.result.length; i++) {
              let temp = res.result[i]
              that.departTree.push(temp)
            }
          } else {
            that.$message.warning(res.message)
          }
        })
      } else {
        that.loadTree()
      }
    },
    setThisExpandedKeys(node) {
      if (node.children && node.children.length > 0) {
        this.iExpandedKeys.push(node.key)
        for (let a = 0; a < node.children.length; a++) {
          this.setThisExpandedKeys(node.children[a])
        }
      }
    },
    refresh() {
      this.loading = true
      this.loadTree()
    },
    onSelect(selectedKeys, e) {
      if (this.selectedKeys[0] !== selectedKeys[0]) {
        this.selectedKeys = [selectedKeys[0]]
      }
      let record = e.node.dataRef
      // this.selectionRows.push(record.id);
      this.onClearSelected()
      this.open(record)
    },
    onClearSelected() {
      this.selectedRowKeys = []
      this.selectionRows = []
    },
    open(record) {
      this.orgCode = record.orgCode
      this.loadData(1)
    },
    // 触发屏幕自适应
    resetScreenSize() {
      let screenWidth = document.body.clientWidth
      if (screenWidth < 500) {
        this.scrollTrigger = { x: 800 }
      } else {
        this.scrollTrigger = {}
      }
    },
    allObj() {
      this.selectedKeys = []
      this.onClearSelected()
      this.orgCode = null
      this.loadData(1)
    },
    getPcaText(code) {
      return this.pcaData.getText(code)
    }
  }
}
</script>
<style scoped>
.ant-card-body .table-operator {
  margin-bottom: 18px;
}

.ant-table-tbody .ant-table-row td {
  padding-top: 15px;
  padding-bottom: 15px;
}

.anty-row-operator button {
  margin: 0 5px;
}

.ant-btn-danger {
  background-color: #ffffff;
}

.ant-modal-cust-warp {
  height: 100%;
}

.ant-modal-cust-warp .ant-modal-body {
  height: calc(100% - 110px) !important;
  overflow-y: auto;
}

.ant-modal-cust-warp .ant-modal-content {
  height: 90% !important;
  overflow-y: hidden;
}

.anty-img-wrap {
  height: 25px;
  position: relative;
}

.anty-img-wrap > img {
  max-height: 100%;
}
</style>
